Technical Q&A QA1037
CGBitmapContextCreate Supported Color Spaces

Q: What color spaces does CGBitmapContextCreate support?

A: CGBitmapContextCreate supports the following combinations for the colorspace (CS), bitsPerComponent (BPC), and alphaInfo parameters:

Table 1: Supported Combinations

CSBPCalphaInfoResulting Bits and Description
NULL8kCGImageAlphaOnlyAAAAAAAA

8 bits per pixel alpha-only destination. Color data is thrown away. Useful for generating alpha channels and masks.

Only supported in Mac OS X 10.3 and later.
Gray8kCGImageAlphaNoneWWWWWWWW

8 bits per pixel grayscale channel.
RGB5kCGImageAlphaNoneSkipFirst-RRRRRGGGGGBBBBB

16 bits per pixel, 5 bits per RGB component.
RGB8kCGImageAlphaNoneSkipFirst--------RRRRRRRRRGGGGGGGGBBBBBBBB

32 bits per pixel, 8 bits per RGB component where first 8 bits are ignored.
RGB8kCGImageAlphaNoneSkipLastRRRRRRRRRGGGGGGGGBBBBBBBB--------

32 bits per pixel, 8 bits per RGB component where last 8 bits are ignored.
RGB8kCGImageAlphaPremultipliedFirstAAAAAAAARRRRRRRRRGGGGGGGGBBBBBBBB

32 bits per pixel, 8 bits per ARGB component with premultiplied alpha.
RGB8kCGImageAlphaPremultipliedLastRRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA

32 bits per pixel, 8 bits per RGBA component with premultiplied alpha.
CMYK8kCGImageAlphaNoneCCCCCCCCMMMMMMMMYYYYYYYYKKKKKKKK

32 bits per pixel, 8 bits per CMYK component without alpha.

Only supported in Mac OS X 10.3 and later.

Table 2: where color spaces are created as follows:

Color SpaceDescription
NULLSimply pass NULL for the colorspace parameter
GrayA color space created with a gray ICC profile or via CGColorSpaceCreateDeviceGray
RGBA color space created with an RGB ICC profile or via CGColorSpaceCreateDeviceRGB
CYMKA color space created with a CMYK ICC profile or via CGColorSpaceCreateDeviceCMYK

Table 3: and the resulting bits are designated as follows:

BitDescription
WWhite
AAlpha
RRed
GGreen
BBlue
CCyan
MMagenta
YYellow
KBlack
-Skip

Document Revision History

DateNotes
2004-09-09Removed two combinations in the Gray color space that had been incorrectly documented as supported.
2004-02-20New Document

Posted: 2004-09-09